var dbConfig = require("../utils/dbconfig");
var express = require("express");
var Response = require("../utils/response");

function getUserBaseInfo(req, res, next) {
  let sql = `select * from base_user`;
  let sqlArr = [];

  var callBack = (err, data) => {
    if (err) {
      console.log("连接出错了");
    } else {
      if (data.length > 0) {
        res.send(new Response(200, "查询成功", data));
      } else {
        res.send(new Response(500, "查询失败", data));
      }
    }
  };
  dbConfig.sqlConnection(sql, sqlArr, callBack);
}

function getDepartment(req, res, next) {
  let sql = `select * from base_department`;
  let sqlArr = [];

  var callBack = (err, data) => {
    if (err) {
      console.log("连接出错了");
    } else {
      if (data.length > 0) {
        res.send(new Response(200, "查询成功", data));
      } else {
        res.send(new Response(500, "查询失败", data));
      }
    }
  };
  dbConfig.sqlConnection(sql, sqlArr, callBack);
}

function getRank(req, res, next) {
  let sql = `select * from base_user_rank`;
  let sqlArr = [];

  var callBack = (err, data) => {
    if (err) {
      console.log("连接出错了");
    } else {
      if (data.length > 0) {
        res.send(new Response(200, "查询成功", data));
      } else {
        res.send(new Response(500, "查询失败", data));
      }
    }
  };
  dbConfig.sqlConnection(sql, sqlArr, callBack);
}

function getPosition(req, res, next) {
  let sql = `select * from base_user_position`;
  let sqlArr = [];

  var callBack = (err, data) => {
    if (err) {
      console.log("连接出错了");
    } else {
      if (data.length > 0) {
        res.send(new Response(200, "查询成功", data));
      } else {
        res.send(new Response(500, "查询失败", data));
      }
    }
  };
  dbConfig.sqlConnection(sql, sqlArr, callBack);
}



module.exports = {
  getDepartment,
  getUserBaseInfo,
  getRank,
  getPosition,
};
